package com.k8.cluster.builder;


import com.k8.cluster.clusterImpl.FailFastCluster;
import com.k8.rpc.cluster.Cluster;
import com.k8.rpc.cluster.ClusterBuilder;
import com.k8.rpc.cluster.loadBalance.LoadBalance;
import com.k8.rpc.url.URL;

/**
 * 根据url参数的选择返回对应类型的ClusterInvoker
 * 目前支持的有FailoverClusterInvoker 调用失败则使用其他实例，可设置失败次数
 * FailbackClusterInvoker 失败时定时重试，适用于通知
 */
public class FailFastClusterBuilder implements ClusterBuilder {
    /*public Cluster build(String clusterName, String balanceName, ExtensionAccessor extensionAccessor){
        ExtensionLoader<Cluster> clusterExtensionLoader = extensionAccessor.getExtensionLoader(Cluster.class);
        ExtensionLoader<LoadBalance> loadBalanceExtensionLoader = extensionAccessor.getExtensionLoader(LoadBalance.class);
        if (clusterName == null || clusterName.isEmpty()){
            clusterName = DEFAULT_CLUSTER;
        }
        if (balanceName == null || balanceName.isEmpty()){
            balanceName = DEFAULT_LOAD_BALANCE;
        }
        Cluster cluster = clusterExtensionLoader.createProtoBean(clusterName);
        if (cluster == null){
            cluster = clusterExtensionLoader.createProtoBean(DEFAULT_CLUSTER);
        }
        LoadBalance balance = loadBalanceExtensionLoader.createProtoBean(balanceName);
        if (balance == null){
            balance = loadBalanceExtensionLoader.createProtoBean(DEFAULT_LOAD_BALANCE);
        }
        cluster.setBalance(balance);
        return cluster;
    }*/
    @Override
    public Cluster build(URL url, LoadBalance loadBalance) {
        FailFastCluster<Object> failFastCluster = new FailFastCluster<>();
        failFastCluster.setBalance(loadBalance);
        return failFastCluster;
    }
}
